<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // let obj = Object.defineProperty({}, "name", {
        //     configurable: true,
        //     enumerable: true,
        //     get(){
        //         console.log('get');
        //         return '张三'
        //     },
        //     set(newValue){
        //         console.log('修改的值：', newValue);
        //     }
        // });

        
        // obj.name;
        // obj.name = '里斯';

        // 修改一个对象
        let obj = {
            name: '张三',
            age: 20
        };

        for(let key in obj){
            let value = obj[key];
            Object.defineProperty(obj, key, {
                configurable: true, 
                enumerable: true,
                get(){
                    console.log('get');
                    return value;
                },
                set(newValue){
                    console.log('set');
                    value = newValue;
                }
            })
        }

        obj.name = '李四';

        console.log(obj);
    </script>
</body>
</html>